fn extract_numbers(input: &str) -> (u32, u32) {
    // 查找括号的位置
    if let Some(open_paren) = input.find('(') {
        let num1 = &input[..open_paren].trim(); // 提取 num1
        let num2 = &input[open_paren + 1..]; // 提取 (num2) 部分

        // 清理 num2 的右括号并解析为 i64
        if let Some(close_paren) = num2.find(')') {
            let num2 = &num2[..close_paren].trim(); // 提取 num2
            let num1_value = num1.parse::<u32>().expect("Failed to parse num1");
            let num2_value = num2.parse::<u32>().expect("Failed to parse num2");
            return (num1_value, num2_value);
        }
    }
    
    panic!("Input format is incorrect");
}

pub fn convert_base(num_str: &str, to_base: u32) -> String {
    let(num1,num2) = extract_numbers(num_str);

    let mut decimal_value = 0;
    let mut power = 1;
    let mut n = num1;

    while n>0 {
        let digit = n%10;
        decimal_value += digit*power;
        power *= num2;
        n /= 10;
    }

    let mut result = String::new();
    let mut decimal_value = decimal_value ;

    if decimal_value == 0 {
        return "0".to_string();
    }

    while decimal_value > 0 {
        let remainder = decimal_value % to_base;
        result.push(std::char::from_digit(remainder, to_base).unwrap());
        decimal_value /= to_base;
    }

    result.chars().rev().collect()
}
